<template>
    <div class="form-body">
        <tool-bar>
            <el-button type="primary" size="small" @click="submitForm" v-loading.fullscreen.lock="fullscreenLoading">保存</el-button>
        </tool-bar>
        <el-container class="container">
            <el-row>
                <el-col :span="24">
                    <div class="breadcrumb">
                        <el-breadcrumb separator="/">
                            <el-breadcrumb-item><i class="el-icon-lx-calendar"></i> 表单</el-breadcrumb-item>
                            <el-breadcrumb-item>枚举管理新增</el-breadcrumb-item>
                        </el-breadcrumb>
                    </div>
                </el-col>
                <el-form  :rules="rules"  ref="form" :label-position="labelPosition"  :model="form" size="small" label-width="120px">
                    <el-col :span="24">
                        <el-card class="card" shadow="hover">
                            <div slot="header" class="clearfix">
                                <center>
                                    <span>基本信息</span>
                                </center>
                            </div>
                                <el-row>
                                <el-col :span="12">
                                    <el-form-item  label="ID"  prop="fdId">
                                        <el-input class="input" v-model="form.fdId"  ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item  label="创建时间"  prop="fdCreateTime">
                                        <el-input class="input" v-model="form.fdCreateTime"  ></el-input>
                                    </el-form-item>
                                </el-col>
                                </el-row>
                                <el-row>
                                <el-col :span="12">
                                    <el-form-item  label="枚举名称" required prop="fdName">
                                        <el-input class="input" v-model="form.fdName" required ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item  label="枚举类型" required prop="fdType">
                                        <el-input class="input" v-model="form.fdType" required ></el-input>
                                    </el-form-item>
                                </el-col>
                                </el-row>
                                <el-row>
                                <el-col :span="12">
                                    <el-form-item  label="系统枚举" required prop="fdIsSystem">
                                        <el-input class="input" v-model="form.fdIsSystem" required ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item  label="备注"  prop="fdRemark">
                                        <el-input class="input" v-model="form.fdRemark"  ></el-input>
                                    </el-form-item>
                                </el-col>
                                </el-row>
                                <el-row>
                                <el-col :span="12">
                                    <el-form-item  label="默认值"  prop="fdDefaultValue">
                                        <el-input class="input" v-model="form.fdDefaultValue"  ></el-input>
                                    </el-form-item>
                                </el-col>
                                    </el-row>
                        </el-card>
                    </el-col>
                </el-form>
            </el-row>
        </el-container>
    </div>
</template>
<script>
import ToolBar from '@/components/form/ToolBar';
import formUtils from '@/utils/formUtils';
export default {
    name: "sysEnumsMainAdd",
    components: {
        ToolBar
    },
    data() {
        return {
            form: {
                fdId:'',
                fdCreateTime:'',
                fdName:'',
                fdType:'',
                fdIsSystem:'',
                fdRemark:'',
                fdDefaultValue:''
            },
            rules:{
                fdName :[{required: true, message: '请输入枚举名称', trigger: 'blur'}],
                fdType :[{required: true, message: '请输入枚举类型', trigger: 'blur'}],
                fdIsSystem :[{required: true, message: '请输入系统枚举', trigger: 'blur'}],
	        },
            labelPosition:'right',
            fullscreenLoading:false
        }
    },
    created() {
        this.initParam();
    },
    methods: {
        submitForm() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    this.fullscreenLoading = true;
                    let forms = formUtils.convertToModel(this.form);
                    this.$put('/api/sys/enums/sys_enums_main',forms).then((res) => {
                        this.fullscreenLoading = false;
                        if(res.status==1){
                            this.$message({
                                message: res.message,
                                type: 'success',
                                onClose: function (){
                                    window.close();
                                }
                            });
                        }else{
                            this.$message.error(res.message);
                        }
                    });

                }
            });
        },
        initParam() {
            let fdId = this.$route.query.id;
            if(formUtils.isNotEmpty(fdId)){
                this.fullscreenLoading = true;
                this.$fetch('/api/sys/enums/sys_enums_main',{
                    id:fdId
                }).then((res) => {
                    console.log(res.data);
                    formUtils.convertToForm(res.data,this.form);
                    console.log(this.form);
                    this.fullscreenLoading = false;
                });
            }
        }
    }
}
</script>
<style scoped >
@import "~@/assets/css/form.css";
</style>